The current libxl_set_memory_target function subtracts a negative amount
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Tue, 1 Feb 2011 19:25:08 +0000 (19:25 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Tue, 1 Feb 2011 19:25:08 +0000 (19:25 +0000)
from an uint32_t variable without checking if the operation wraps
around.

This patch fixes this bug (that I previously believed to be an
hypervisor issue):
http://bugzilla.xensource.com/bugzilla/show_bug.cgi?id=1729

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl.c

index 2d2b884baf34765da5d37ab8869d2a2cdd1f3464..538932948df9550647f092c0f0b55bd1dd2d2a20 100644 (file)
@@ -2059,9 +2059,12 @@ retry_transaction:
         goto out;
     }
 
-    if (relative)
-        new_target_memkb = current_target_memkb + target_memkb;
-    else
+    if (relative) {
+        if (target_memkb < 0 && abs(target_memkb) > current_target_memkb)
+            new_target_memkb = 0;
+        else
+            new_target_memkb = current_target_memkb + target_memkb;
+    } else
         new_target_memkb = target_memkb;
     if (new_target_memkb > memorykb) {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR,